// index.js
// 获取应用实例
const app = getApp()
import {Painter} from './painter'
import {image} from './data'
Page({
  data: {},
  async onLoad() {
    const res = await this.getCentext()
    const painter = new Painter(res)
    // 装载数据
    await painter.source(image)
    console.log('image', image)
    // 渲染
    await painter.render()
  },
  // 获取canvas 2d
    // 非2d也可以使用这里只是举个例子
    getCentext() {
      return new Promise(resolve => {
          wx.createSelectorQuery()
          .select(`#lime-painter`)
          .node()
          .exec(res => {
              let { node: canvas } = res[0];
              resolve({
                  canvas, 
                  context: canvas.getContext('2d'),
                  width: canvas.width,
                  height: canvas.height,
                  pixelRatio: 2
            }) 
          })
      })
  },
})
